//
//  XPBaseViewController.swift
//  PPKit
//
//  Created by xiaopin on 16/8/31.
//  Copyright © 2016年 pinguo. All rights reserved.
//  https://gitee.com/xiaopindev/PPKit
//  https://github.com/xiaopindev
//  https://xiaopin.cnblogs.com

import UIKit
import Toast_Swift
import SwiftyAttributes
import Kingfisher

@objcMembers
class XPBaseViewController: UIViewController {

    //MARK: 属性
    /// 临时属性x,y,width,height
    var tempX:CGFloat = 0,tempY:CGFloat=0,tempW:CGFloat = 0,tempH:CGFloat = 0
    /// 键盘高度
    var keyboardHeight:CGFloat = 0
    /// 是否正在操作中
    var isActioning:Bool = false
    /// 页面是否是第一次加载过
    var isFirstLoaded:Bool = false
    /// 提示
    var alertView = UIView()
    /// 导航push来源
    var pushSource:PushSource = .default
    
    /// 版本信息提示
    lazy var updateView:XPUpdateView = {
        let view:XPUpdateView = XPUpdateView.loadFromNib()
        view.tag = 1666
        view.frame = CGRect(x: 0, y: 0, width: pp_screen_width, height: pp_screen_height)
        return view
    }()
    
    lazy var loadingAnimateView:UIImageView = {
        let loadingView = UIImageView(frame: pp_frame(0, 0, 50, 50))
        var images = [UIImage]()
        for i in 1..<9 {
            images.append(UIImage(named: "animation_loading_\(i)")!)
        }
        if images.count > 0 {
            loadingView.animationImages = images
            loadingView.animationDuration = 5
            loadingView.startAnimating()
        }
        return loadingView
    }()
    
    //待补充
    var emptyDataView = UIView()
    
    //无网络提示：导航栏下面提示
    lazy var netErrorView: XPNetErrorTipView = {
        let view = XPNetErrorTipView(frame: pp_frame(0, 0, pp_screen_width, 40))
        view.clickClosure = {[weak self] () in
            self?.toNetConfigGuide()
        }
        return view
    }()
    
    //无网络提示：页面中心提示
    lazy var networkHintView: UIView = {
        let bgView = UIView(frame: pp_frame(0, pp_screen_navbar_height, pp_screen_width, pp_screen_height - pp_screen_navbar_height))
        bgView.backgroundColor = pp_color(.CFFFFFF)
        
        let infoView = UIView(frame: pp_frame(0, pp_screen_navbar_height + 60, bgView.width, 153 + 15 + 20 + 15 + 33))
        
        let imgView = UIImageView()
        imgView.frame = CGRect(x: 0, y: 0, width: infoView.width, height: 153)
        imgView.image = UIImage(named: "mt_nonetwork")
        imgView.contentMode = .scaleAspectFit
        infoView.addSubview(imgView)
        
        let label = UILabel(frame: pp_frame(0, imgView.top + imgView.height + 15, infoView.width, 20))
        label.text = "MT_NoNetwork".localized
        label.textColor = #colorLiteral(red: 0.6000000238, green: 0.6000000238, blue: 0.6000000238, alpha: 1)
        label.font = .systemFont(ofSize: 14)
        label.textAlignment = .center
        infoView.addSubview(label)
        
        let button = UIButton()
        button.frame = pp_frame(0, label.top + label.height + 15, 125, 33)
        button.setBackgroundImage(UIImage.gradientImage(CGSize(width: 125, height: 34), #colorLiteral(red: 0.2235294118, green: 0.6156862745, blue: 0.9803921569, alpha: 1), #colorLiteral(red: 0.1960784314, green: 0.4196078431, blue: 0.9803921569, alpha: 1)), for: .normal)
        button.setTitle("重新加载", for: .normal)
        button.cornerRadius = 4
        button.titleLabel?.font = .systemFont(ofSize: 14)
        button.center = CGPoint(x: bgView.center.x, y: label.top + label.height + 30)
        button.addTarget(self, action: Selector(("reloadNewData")), for: .touchUpInside)
        infoView.addSubview(button)
        
        bgView.addSubview(infoView)
        return bgView
    }()
    
    
    //MARK: 系统函数
    deinit{
        NotificationCenter.default.removeObserver(self)
        //PPLog("退出程序，释放资源...")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        NotificationCenter.default.addObserver(self, selector: #selector(self.loginStateChanged(_:)), name: .xpfLoginStatusChanged, object: nil)
        NotificationCenter.default.addObserver(self, selector: #selector(self.languageChanged(_:)), name: .xpfLanguageChanged, object: nil)
        NotificationCenter.default.addObserver(self, selector: #selector(self.networkChanged(_:)), name: .xpfNetworkChanged, object: nil)
        NotificationCenter.default.addObserver(self,selector: #selector(keyboardWillShow(_:)),name: .xpfKeyboardWillShow,object: nil)
        NotificationCenter.default.addObserver(self,selector: #selector(keyboardDidShow(_:)),name: .xpfKeyboardDidShow,object: nil)
        NotificationCenter.default.addObserver(self,selector: #selector(keyboardWillHide(_:)),name: .xpfKeyboardWillHide,object: nil)
        NotificationCenter.default.addObserver(self,selector: #selector(keyboardDidHide(_:)),name: .xpfKeyboardDidHide,object: nil)
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        //MobClick.beginLogPageView(#file)
//        navigationController?.setNavigationBarHidden(hideNavBar,animated:true)
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
    }
    
    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        
        //MobClick.endLogPageView(#file)
    }
    
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        
        /*
        //以下代码解决导航栏，左边距问题
        if let items = self.navigationItem.leftBarButtonItems{
            let item1 = items.first
            let view = item1?.customView?.superview?.superview?.superview
            if let constraints = view?.constraints {
                for con in constraints {
                    if abs(con.constant) == 16 || abs(con.constant) == 20 {
                        con.constant = 0
                    }
                }
            }
        }
        //以下代码解决导航栏，右边距问题
        if let items = self.navigationItem.rightBarButtonItems{
            let item1 = items.first
            let view = item1?.customView?.superview?.superview?.superview
            if let constraints = view?.constraints {
                for con in constraints {
                    if abs(con.constant) == 16 || abs(con.constant) == 20 {
                        con.constant = 0
                    }
                }
            }
        }
        */
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    /// 设备特征变更
    override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
        super.traitCollectionDidChange(previousTraitCollection)
        
        if #available(iOS 13.0, *){
            if traitCollection.hasDifferentColorAppearance(comparedTo: previousTraitCollection){
                //系统切换了外观模式：浅色、深色
                PPLog("XPBaseViewController hasDifferentColorAppearance")
                themeModeChanged()
            }
        }
    }
}

//MARK: #自定义方法#
extension XPBaseViewController{
    /**
     初始化页面数据
     
     在这个函数里面可以初始化控制器页面所有需要的属性、对象数初始值
     */
    func initData() {
        
    }
    
    /**
     初始化通知
     
     存放当前控制器所有NotificationCenter通知注册回调，也可以在这个函数中输入xpnotify会自动弹出代码块快速生成，如下：
     
     NotificationCenter.default.addObserver(forName: 通知名, object: nil, queue: .main) { (notify) in
         执行的代码
     }
     */
    func initNotification(){
        
        
    }
    
    /**
     初始化导航栏
     
     存放控制前页面导航栏初始化UI, 标题，左右操作项，该函数是苹果系统级导航栏，如特殊情况的自定义导航栏UI，自行创建一个继承UIView的类画好界面，然后再view.addSubview(CustomNavBar),添加到控制器中
     */
    func initNavigationBar() {
        
        //返回按钮
        let leftButton = UIBarButtonItem(image: UIImage(named: "nav_back"), style: UIBarButtonItem.Style.plain, target: self, action: #selector(backAction))
        self.navigationItem.leftBarButtonItem = leftButton
        
        //标题
        let titleLabel = UILabel(frame: CGRect(x: 0,y: 0,width: 190,height: 20))
        titleLabel.textColor = pp_color(.C222222)
        titleLabel.text = self.title
        titleLabel.textAlignment = .center
        titleLabel.font = UIFont.boldSystemFont(ofSize: 17)
        self.navigationItem.titleView = titleLabel
    }
    
    /**
     初始化导航栏，如果有2套导航栏样式，第二套样式就调用此方法： super.initNavigationBar2()
     
     存放控制前页面导航栏初始化UI, 标题，左右操作项，该函数是苹果系统级导航栏，如特殊情况的自定义导航栏UI，自行创建一个继承UIView的类画好界面，然后再view.addSubview(CustomNavBar),添加到控制器中
     */
    func initNavigationBar2() {
        //设置导航栏样式
        self.navigationController?.navigationBar.barTintColor = pp_color(.C159F48)
        self.navigationController?.navigationBar.tintColor = .white
        
        //设置字体和大小
        self.navigationController?.navigationBar.titleTextAttributes = {[
            NSAttributedString.Key.foregroundColor:UIColor.white,
            NSAttributedString.Key.font:UIFont.boldSystemFont(ofSize: 17)
            ]}()
        
        self.navigationController?.navigationBar.setBackgroundImage(navBackImageWithColor(.white), for: .default)
        
        //返回按钮
        let leftButton = UIBarButtonItem(image: UIImage(named: "nav_back"), style: UIBarButtonItem.Style.plain, target: self, action: #selector(backAction))
        self.navigationItem.leftBarButtonItem = leftButton
        
        //标题
        let titleLabel = UILabel(frame: CGRect(x: 0,y: 0,width: 190,height: 20))
        titleLabel.textColor = .white
        titleLabel.text = self.title
        titleLabel.textAlignment = .center
        titleLabel.font = UIFont.boldSystemFont(ofSize: 17)
        self.navigationItem.titleView = titleLabel
    }
    
    /**
     初始化页面元素
     
     存放控制器页面的UI控件代码，创建、添加到view等。也可以在私有属性和懒加载mark部分写好快捷的UI控件代码，在此方法中添加到控制器View中
     */
    func initSubViews() {
        view.backgroundColor = pp_color(.CFFFFFF)
        
        edgesForExtendedLayout = []
        
        if #available(iOS 11, *) {
        } else {
            automaticallyAdjustsScrollViewInsets = false
        }
    }
    
    /**
     加载数据
     
     首次加载的时候会调用此方法，根据页面简单复杂情况来写自己的数据请求和加载逻辑
     */
    func loadData() {
        
    }
    /**
     加载缓存数据
     
     加载缓存数据的逻辑在此方法中编写
     */
    func loadCacheData() {
        
    }
    
    /// 加载国际化
    func loadLocalString(){
        
    }
    
    /**
     刷新布局
     
     如果页面需要交互逻辑控制和刷新布局，可以重写该方法，在该方法中编写刷新布局的逻辑
     */
    func refreshLayout(){
        
    }

    /**
     导航标题
     
     :param: title <#title description#>
     */
    func titleView(_ title:String?=""){
        self.title = title
        let titleLabel = UILabel(frame: CGRect(x: 0,y: 0,width: 190,height: 20))
        titleLabel.textColor = pp_color(.C222222)
        titleLabel.text = self.title
        titleLabel.textAlignment =  NSTextAlignment.center
        titleLabel.font = UIFont.boldSystemFont(ofSize: 17)
        self.navigationItem.titleView = titleLabel
    }
    
    func backAction() {
        self.hideLoading()
        self.navigationController?.popViewController(animated: true)
    }
    
    
    /// 显示默认导航栏
    ///
    /// 如果当前控制器需要显示系统的导航栏，在控制器的viewWillAppear方法中调用此方法
    /// - Parameter animated: 直接把viewWillAppear的参数带进来
    func showNavigationBar(_ animated:Bool = true){
        self.navigationController?.setNavigationBarHidden(false, animated: animated)
    }
    
    
    /// 隐藏默认导航栏
    ///
    /// 如果当前控制器需要隐藏系统的导航栏，在控制器的viewWillAppear方法中调用此方法
    /// - Parameter animated: <#animated description#>
    func hideNavigationBar(_ animated:Bool = true){
        self.navigationController?.setNavigationBarHidden(true, animated: animated)
    }
    
    private func findHairlineImageViewUnder(_ view:UIView?) -> UIImageView?{
        guard let v = view else { return nil }
        if v.isKind(of: UIImageView.classForCoder()) && v.bounds.size.height <= 1.0 {
            return view as? UIImageView
        }
        for subview in v.subviews {
            if let imageView = self.findHairlineImageViewUnder(subview) {
                return imageView
            }
        }
        return nil
    }
    
    
    /// 导航栏底部的线变色
    ///
    /// 如果需要变更系统导航栏底部的分割线颜色，调用此方法
    /// - Parameter bgColor: <#bgColor description#>
    func navBarBottomLineBgColor(_ bgColor:UIColor? = nil){
        let imageView = self.findHairlineImageViewUnder(self.navigationController?.navigationBar)
        imageView?.isHidden = false
        if let color = bgColor {
            imageView?.backgroundColor = color
        }
    }
    
    /// 隐藏导航栏底部的线
    ///
    /// 如果当前控制器不需要系统导航栏默认的底部线条，调用此方法隐藏
    func hideNavBarBottomLine(){
        let imageView = self.findHairlineImageViewUnder(self.navigationController?.navigationBar)
        imageView?.isHidden = true
    }
    
    //MARK: 页面跳转
    /// 系统导航栏推出控制器简写写法
    ///
    /// 每次都要写 self.navigationController?.pushViewController(pushVC, animated: animated) 一长串很麻烦，直接push(vc) 简写解决
    /// - Parameters:
    ///   - pushVC: 要推出的控制器对象
    func push(_ pushVC:UIViewController){
        pushVC.hidesBottomBarWhenPushed = true
        self.navigationController?.pushViewController(pushVC, animated: true)
    }
    
    /// 弹出登录页面
    func toLoginPageByModal(){
//        let loginVC = MTLoginRegisterController()
//        let navVC = XPNavigationController(rootViewController: loginVC)
//        navVC.modalTransitionStyle = UIModalTransitionStyle.coverVertical
//        navVC.modalPresentationStyle = .fullScreen
//        present(navVC, animated: true)
    }

    func toLoginPage(){
//        let loginVC = MTLoginRegisterController()
//        let navVC = XPNavigationController(rootViewController: loginVC)
//        navVC.modalTransitionStyle = UIModalTransitionStyle.coverVertical
//        navVC.modalPresentationStyle = .fullScreen
//        self.present(navVC, animated: true)
    }
        
    /// 跳转到个人主页
    func toPersonalPage(_ userId:Int = 0) {
//        if userId == 0 {return}
//        let vc = MTUserDetailController()
//        vc.userId = userId
//        push(vc)
    }
    
    /// 广告点击
//    func adTapAction(_ model:MTAdModel){
//        XPNetworkApi.shared.common_ad_stat(adId: model.id, type: 1)
//        switch model.object_type {
//        case 3:
//            let vc = MTWebViewController()
//            vc.title = model.core_name
//            vc.webUrl = model.url
//            push(vc)
//        case 8:
//            if let str = model.url, let url = URL(string: str) {
//                UIApplication.shared.open(url, options: [:], completionHandler: nil)
//            }
//        default:
//            break
//        }
//    }
    
    //MARK: 页面强制横竖屏幕切换
    func setNewOrientation(_ fullscreen:Bool){
        if (fullscreen) {
            let resetOrientationTarget = NSNumber(value: UIInterfaceOrientation.unknown.rawValue)
            UIDevice.current.setValue(resetOrientationTarget, forKey: "orientation")
            
            let orientationTarget = NSNumber(value: UIInterfaceOrientation.landscapeRight.rawValue)
            UIDevice.current.setValue(orientationTarget, forKey: "orientation")
        }else{
            let resetOrientationTarget = NSNumber(value: UIInterfaceOrientation.unknown.rawValue)
            UIDevice.current.setValue(resetOrientationTarget, forKey: "orientation")
            
            let orientationTarget = NSNumber(value: UIInterfaceOrientation.portrait.rawValue)
            UIDevice.current.setValue(orientationTarget, forKey: "orientation")
        }
    }
    
    /// 系统默认风向
    /// - Parameters:
    ///   - text: 分享标题
    ///   - imageUrl: 分享图片地址，http://img.tysondata.com/league/20180131/20180131115815792_280x280.png
    ///   - linkUrl: 分享链接
    func shareContent(text:String = "", imageUrl:String = "", link:String = ""){
        var items = [Any]()
        items.append(text)
        if let url = URL(string: imageUrl), let data = try? Data.init(contentsOf:url) , let image = UIImage(data: data){
            items.append(image)
        }
        if let shareUrl = URL(string: link) {
            items.append(shareUrl)
        }
    
        let shareVC = UIActivityViewController.init(activityItems: items, applicationActivities: nil)
        shareVC.isModalInPresentation = true
        shareVC.completionWithItemsHandler = { activityType, completed, returnedItems, activityError in
            if completed {
                PPLog("分享成功")
            }else{
                PPLog("分享失败")
            }
            if let error = activityError {
                PPLog("分享错误:\(error)")
            }
        }
        present(shareVC, animated: true)
    }
    
    func checkVerInfo(){
        updateView.removeFromSuperview()
//        XPNetworkApi.shared.common_fetchServerVerInfo({ [weak self] (msg, count, res) in
//            guard let result = res as? [String:Any] else{return}
//            let isForce = result["update_install"] as? Bool
//            let notes = result["update_log"] as? String
//            let downloadUrl = result["download_url"] as? String
//            if let window = pp_keyWindow(), let updateView = self?.updateView {
//                guard window.viewWithTag(1666) == nil else { return }
//                updateView.customInfo(isForce, notes, downloadUrl)
//                window.addSubview(updateView)
//            }
//        })
//        XPNetworkApi.shared.common_fetchAppStoreInfo({ [weak self] (msg, count, data) in
//            let appInfo = data as! XPAppStoreInfo
//
//            XPApplication.shared.appStoreInfo = appInfo
//
//            if appInfo.version?.isEmpty ?? true {return}
//            var canAlert = false
//
//            let arrayRemote = appInfo.version?.components(separatedBy: ".")
//            let arrayLocal = pp_AppVersion.components(separatedBy: ".")
//
//            let remote1:Int = Int(arrayRemote![0])!
//            let remote2:Int = Int(arrayRemote![1])!
//            let remote3:Int = Int(arrayRemote![2])!
//
//            let local1:Int = Int(arrayLocal[0])!
//            let local2:Int = Int(arrayLocal[1])!
//            let local3:Int = Int(arrayLocal[2])!
//
//            if remote1 > local1 {
//                canAlert = true
//            }else if remote1 == local1 {
//                if remote2 > local2 {
//                    canAlert = true
//                }else if remote2 == local2 {
//                    if(remote3 > local3){
//                        canAlert = true;
//                    }
//                }
//            }
//
//            if canAlert {
//                let window:UIWindow = UIApplication.shared.keyWindow!
//                window.addSubview(self!.updateView)
//                self?.updateView.customInfo(false, appInfo.releaseNotes, AppStoreDownUrl)
//            }
//        }) { [weak self] (msg, code) in
//            self?.isActioning = false
//            //logger.info("\(msg) :>>\(code)")
//        }
    }
    
    func reloadNewData(){
       
    }

    /// 显示网络错误提示
    /// - Parameters:
    ///   - isShow: 是否显示
    ///   - viewAll: 是否全屏
    func showNetworkHint(_ isShow: Bool = true, _ viewAll:Bool = false) {
        if isShow {
            self.networkHintView.removeFromSuperview()
            if self.navigationController?.isNavigationBarHidden == true && !viewAll {
                self.networkHintView.top = pp_screen_navbar_height
                self.networkHintView.height = pp_screen_height - pp_screen_navbar_height
            }else{
                self.networkHintView.top = 0
                self.networkHintView.height = pp_screen_height
            }
            self.view.addSubview(self.networkHintView)
        } else {
            self.networkHintView.removeFromSuperview()
        }
    }
    
    //跳转到网络配置指引
    func toNetConfigGuide(){
        let vc = XPNetErrorGuideViewController()
        self.push(vc)
    }
    
    //MARK: 消息提示
    func showLoading() {
        ToastManager.shared.style.backgroundColor = pp_color(#colorLiteral(red: 0.2, green: 0.2, blue: 0.2, alpha: 0.8), #colorLiteral(red: 0.1529411765, green: 0.1529411765, blue: 0.1882352941, alpha: 1))
        self.view.makeToastActivity(.center)
    }
    
    func hideLoading() {
        self.view.hideToastActivity()
    }
    
    /// 显示gif中间加载动画
    /// - Parameter offset: 线上偏移量
    func showLoading2(_ offset:CGFloat = 0) {
        loadingAnimateView.center = CGPoint(x: self.view.center.x, y: self.view.center.y - offset)
        view.addSubview(self.loadingAnimateView)
        view.bringSubviewToFront(loadingAnimateView)
    }
    
    func hideLoading2() {
        if loadingAnimateView.isAnimating{
            loadingAnimateView.stopAnimating()
        }
        loadingAnimateView.removeFromSuperview()
    }
    
    //MARK: 手势
    func addSwipeLeftGesture() {
        let swipeGesture:UISwipeGestureRecognizer = UISwipeGestureRecognizer.init(target: self, action: #selector(self.swipeGesture(_:)))
        swipeGesture.direction = UISwipeGestureRecognizer.Direction.left
        self.view.addGestureRecognizer(swipeGesture)
    }
    
    func addSwipeRightGesture() {
        let swipeGesture:UISwipeGestureRecognizer = UISwipeGestureRecognizer.init(target: self, action: #selector(self.swipeGesture(_:)))
        swipeGesture.direction = UISwipeGestureRecognizer.Direction.right
        self.view.addGestureRecognizer(swipeGesture)
    }
}

//MARK: #事件通知#
extension XPBaseViewController{
    
    /// 网络变化通知
    ///
    /// 网络发生变化，控制器重写以后，编写处理业务交互逻辑， let netEnv = notify.object as! NetEnv 获取网络
    /// - Parameter notify: <#notify description#>
    func networkChanged(_ notify:Notification) {
        let netEnv = notify.object as! NetEnv
        if netEnv != .unavailable {
            loadData()
        }
    }
    
    /// 登录状态发生改变
    ///
    /// 如果登录、退出登录、登录状态过期等情况导致发生事件，会触发此通知方法，控制器重写以后，编写因登录状态发生改变的业务逻辑
    /// - Parameter notify: <#notify description#>
    func loginStateChanged(_ notify:Notification) {
        
    }
    
    /// 语言切换发生改变
    ///
    /// 如果应用支持多语言，通过设置，语言发生改变，会触发此通知方法
    /// - Parameter notify: <#notify description#>
    func languageChanged(_ notify:Notification) {
        DispatchQueue.main.async {
            self.loadData()
            self.loadLocalString()
        }
    }
    
    /// 键盘即将显示
    /// - Parameter notify: <#notify description#>
    func keyboardWillShow(_ notify:Notification) {
        //得到键盘frame
        let userInfo: NSDictionary = notify.userInfo! as NSDictionary
        let value = userInfo.object(forKey: UIResponder.keyboardFrameEndUserInfoKey)
        let keyboardRec = (value as AnyObject).cgRectValue
        keyboardHeight = keyboardRec?.size.height ?? 0
        PPLog("keyboardWillShow keyboardHeight:\(keyboardHeight)")
    }
    
    /// 键盘已经显示
    func keyboardDidShow(_ notify:Notification) {
        //得到键盘frame
        let userInfo: NSDictionary = notify.userInfo! as NSDictionary
        let value = userInfo.object(forKey: UIResponder.keyboardFrameEndUserInfoKey)
        let keyboardRec = (value as AnyObject).cgRectValue
        keyboardHeight = keyboardRec?.size.height ?? 0
        PPLog("keyboardDidShow keyboardHeight:\(keyboardHeight)")
    }
    
    /// 键盘即将隐藏
    func keyboardWillHide(_ notify:Notification) {
        keyboardHeight = 0
    }
    
    /// 键盘已经隐藏
    func keyboardDidHide(_ notify:Notification) {
        
    }
    
    /// 主题类型发生改变
    ///
    /// 如果切换浅色、深色模式、或其他自定义主题，会触发此方法，控制器可以重写次方法类刷新页面UI
    func themeModeChanged(){
        
    }

    func swipeGesture(_ gesture:UISwipeGestureRecognizer) {
        switch gesture.direction {
        case UISwipeGestureRecognizer.Direction.left:
            PPLog("Left")
        case UISwipeGestureRecognizer.Direction.right:
            self.backAction()
        case UISwipeGestureRecognizer.Direction.up:
            PPLog("Up")
        case UISwipeGestureRecognizer.Direction.down:
            PPLog("Down")
        default:
            PPLog("Default")
        }
    }
}


